#include "Frog.h"
#include "FrogSketcher.h"
#include "BallGenerator.h"
#include <math.h>
Frog::Frog() {
	this->setType("Frog");
}

Frog::Frog(Position *position) {
	this->setPosition(position);
	
}

Frog::Frog(Position *position,float radius) {
	this->setRadius(radius);
	Frog::Frog(position);
}

Frog::Frog(Position *position,float radius,Color * color) {
	this->setElementColor(color);
	Frog::Frog(position,radius);
}

Frog::Frog(Position *position,float radius,Texture *texture) {
	this->setTexture(texture);
	Frog::Frog(position,radius);
}


/*-------------Getters & Setters--------------------*/


void Frog::setInitialized(bool initialized){
	this->initialized=initialized;
}

bool Frog::getInitialized(){
	return this->initialized;
}

void Frog::setPosition(Position *position){
	this->position = position;
}

Position *Frog::getPosition(){
	return this->position;
}

Color * Frog::getElementColor(){
	return this->elementColor;
}

void Frog::setElementColor(Color * color){
	this->elementColor = color;
}

float Frog::getRadius(){
	return this->radius;
}

void Frog::setRadius(float radius){
	this->radius = radius;
}

Texture *Frog::getTexture(){
	return this->texture;
}

void Frog::setTexture(Texture *texture){
	this->texture = texture;
}

void Frog::setMainBall(Ball *ball){
	this->mainBall = ball;
}

void Frog::setSecondaryBall(Ball *ball){
	this->secondaryBall = ball;
}

Ball * Frog::getMainBall(){
	return this->mainBall;
}

Ball * Frog::getSecondaryBall(){
	return this->secondaryBall;
}

float Frog::getMinXPos(){
	return this->getPosition()->getAxisX()-this->radius;
}

float Frog::getMinYPos(){	
	return this->getPosition()->getAxisY()-this->radius;
}

float Frog::getMaxXPos(){	
	return this->getPosition()->getAxisX()+this->radius;
}

float Frog::getMaxYPos(){
	return this->getPosition()->getAxisY()+this->radius;
}

Color * Frog::getLineColor() {
	return this->lineColor;
}

void Frog::setLineColor( Color * color ) {
	this->lineColor = color;
}

void Frog::setAngle(int angle)
{
	this->angle = angle;
}

int Frog::getAngle()
{
	return this->angle;
}


/*---------------Metodos----------------------------*/
void Frog::draw() {
	Sketcher* sketcher = new FrogSketcher(this);
	sketcher->draw();
	delete(sketcher);
}

/*Este metodo deberia ser ejecutado al inicializar el sapo*/
void Frog::initialiceBalls(){
	initialized = true;
	Position *p = new Position(this->position->getPixelX(),this->position->getPixelY());
	this->mainBall = BallGenerator::getInstance()->getBall();
	this->mainBall->setPosition(p);
	/*Decidir de donde sacar los colores*/

	/*Definir position de la bola secundaria*/
	Position *psec = new Position(this->position->getPixelX(),this->position->getPixelY());
	this->secondaryBall = BallGenerator::getInstance()->getBall();
	this->secondaryBall->setPosition(psec);
}

void Frog::reBuildBalls(){
	this->mainBall = secondaryBall;
	Position *p = new Position(this->position->getPixelX(),this->position->getPixelY());
	this->secondaryBall =BallGenerator::getInstance()->getBall();
	this->secondaryBall->setPosition(p);
	/*Decidir de donde sacar los colores*/
}


Ball* Frog::fireBall(Position* p,float velocityModule){
	if(!initialized){
		this->initialiceBalls();
	}
	Ball* auxiliar=this->mainBall;
	this->reBuildBalls();
	double angle = SketcherHelper::getInstance()->calcAngle(*(this->position),*p);
	auxiliar->setInitialPosition(new Position(this->position->getPixelX(),this->position->getPixelY()));
	Velocity* velocity= new Velocity(velocityModule*cos(angle),velocityModule*sin(angle));
	auxiliar->setVelocity(velocity);
	return auxiliar;
}
void Frog::swapBalls(){
	Ball* auxiliar;
	auxiliar = secondaryBall;
	secondaryBall = mainBall;
	mainBall = auxiliar;
}

/*---------------Destructor----------------------------*/

Frog::~Frog() {
	delete(this->texture);
	delete(this->position);
	delete(this->mainBall);
	delete(this->secondaryBall);
}